#include <vector>

#include "particle/Particle.h"
#include "particle/PID.h"
#include "event/BelleEvent.h"
#include "tuple/BelleTupleManager.h"
#include "basf/module.h"
#include "basf/module_descr.h"

#include "eid/eid.h"

#include "panther/panther.h"
#include MDST_H
#include HEPEVT_H

#include "mdst/Muid_mdst.h"

using std::vector;

#ifdef BELLE_NAMESPACE
namespace Belle {
#endif //BELLE_NAMESPACE

  class ypipi_h5: public Module {
  public:
    ypipi_h5();
    virtual ~ypipi_h5();
    void init(int *);
    void term();
    void disp_stat(const char*);
    void hist_def();
    void event(BelleEvent*, int*);
    void begin_run(BelleEvent*, int*);
    void end_run(BelleEvent*, int*);

  };

  extern "C" Module_descr *mdcl_ypipi_h5()
  {
    Module_descr *dscr = new Module_descr ( "ypipi_h5", new ypipi_h5);
    return dscr;
  }
  
  void ypipi_h5::init(int* status) {
    // Whatever!
  }
  
  void ypipi_h5::hist_def() {
    // Define ntuples here
  }


  void ypipi_h5::begin_run(BelleEvent* be, int* status) {
    // No sir
  }
 
  void ypipi_h5::event(BelleEvent *evptr, int *status) {
    vector<Particle> v_eplus;
    vector<Particle> v_eminus;
    vector<Particle> v_muplus;
    vector<Particle> v_muminus;
    vector<Particle> v_pip;
    vector<Particle> v_pim;
    vector<Particle> v_pi0;
  
    Ptype ptype_pi_plus("PI+");
    Ptype ptype_pi_minus("PI-");
    Ptype ptype_muon_plus("MU+");
    Ptype ptype_muon_minus("MU-");
    Ptype ptype_positron("E+");
    Ptype ptype_electron("E-");

    Mdst_charged_Manager& m_charged = Mdst_charged_Manager::get_manager();

    for (Mdst_charged_Manager::iterator i=m_charged.begin();
	 i != m_charged.end(); ++i)
      {
	Mdst_trk& trk(i->trk());
	Muid_mdst muid(*i);

	if (muid.Muon_likelihood() < 0.1)
	  continue;
	
	if (i->charge() > 0.0) {
	  Particle tmp(*i, ptype_muon_plus);
	  v_muplus.push_back(tmp);
	}
      }
        
  }
  
  void ypipi_h5::end_run(BelleEvent* be, int* status) { 
    // Yessir
  }

  void ypipi_h5::term() {
    // End of analysis, close ntuples
  }

  

#ifdef BELLE_NAMESPACE
}
#endif
